package cn.akwangl.concurrency.web.exception;

import cn.akwangl.concurrency.web.common.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理.
 *
 * @author youyongkun
 * @date 2022/5/17 21:41
 */
@RestControllerAdvice
public class CustomExceptionHandler {

    private static final Logger log = LoggerFactory.getLogger(CustomExceptionHandler.class);


    /**
     * 业务异常处理.
     *
     * @param biz 业务自定义异常
     * @return Result
     * @author youyongkun
     * @date 2022/5/17 21:40
     * @since 0.0.2
     */
    @ExceptionHandler(BizException.class)
    public Result handlerMaxUploadFile(BizException biz) {
        return Result.errorMsg(biz.getMessage());
    }

    /**
     * 系统异常统一处理.
     *
     * @param e Exception
     * @return Result
     * @author youyongkun
     * @date 2022/5/17 21:44
     */
    @ExceptionHandler(Exception.class)
    public Result handlerMaxUploadFile(Exception e) {
        log.error("系统调用异常:", e);
        return Result.errorMsg("网络开小差了,请稍后再试");
    }
}